
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace GiftNet.Model
{
	#region UserLog Model -(by fangyifeng at 2007-09-14 12:24:26)

	/// <summary>
	/// UserLog object'UserLog'.
	/// </summary>
	[Serializable]
	public class UserLog : System.IComparable
		{
		#region Member Variables
		
		protected Guid _id;
		protected string _logContent;
		protected DateTime _logDate;
		protected string _logTitle;
		protected SystemUser _systemUser;
		
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public UserLog() { }

		public UserLog(Guid id, string logContent, DateTime logDate, string logTitle, SystemUser systemUser )
		{
            this._id = id;
			this._logContent = logContent;
			this._logDate = logDate;
			this._logTitle = logTitle;
			this._systemUser = systemUser;
		}

		#endregion

		#region Public Properties

		public virtual Guid Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public virtual string LogContent
		{
			get { return _logContent; }
			set
			{
				if ( value != null && value.Length > 1000)
					throw new ArgumentOutOfRangeException("Invalid value for LogContent", value, value.ToString());
				_logContent = value;
			}
		}

		public virtual DateTime LogDate
		{
			get { return _logDate; }
			set { _logDate = value; }
		}

		public virtual string LogTitle
		{
			get { return _logTitle; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for LogTitle", value, value.ToString());
				_logTitle = value;
			}
		}

		public virtual SystemUser SystemUser
		{
			get { return _systemUser; }
			set { _systemUser = value; }
		}

		
        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
			if (!(obj is UserLog))
				throw new InvalidCastException("This object is not of type UserLog");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((UserLog)obj).Id);
					break;
				case "LogContent":
					relativeValue = this.LogContent.CompareTo(((UserLog)obj).LogContent);
					break;
				case "LogDate":
					relativeValue = this.LogDate.CompareTo(((UserLog)obj).LogDate);
					break;
				case "LogTitle":
					relativeValue = this.LogTitle.CompareTo(((UserLog)obj).LogTitle);
					break;
                default:
                    goto case "Id";
			}
            if (UserLog.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
